import Vue from 'vue'
import VueRouter from 'vue-router'
// 静态引入路由
import HomeView from '../views/HomeView.vue'
import AboutView from '../views/AboutView.vue'
import LoginView from '../views/LoginView.vue'
import Classify from '../views/Classify.vue'

/**
 * 通过import 动态引入的代码。会有代码分割的功能（也就是熟称的路由懒加载）
 * 重定向，想让这个项目一进入页面就显示哪个具体指定的页面
 */
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout/home',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/LoginView.vue'),
  },
  // 动态路由
  {
    path: '/detail/:id',
    name: 'detail',
    component: () => import(/* webpackChunkName: "detail" */ '../views/Detail.vue'),
  },
  {
    path: '/layout',
    name: 'layout',
    component: () => import('@/layouts/index.vue'),
    // 二级路由 -> path不添加 /
    children: [
      {
        path: 'home',
        name: 'home',
        component: HomeView,
      },
      {
        path: 'about',
        name: 'about',
        // 动态引入，也叫路由懒加载
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
      },
      {
        path: 'classify',
        name: 'classify',
        component: () => import(/* webpackChunkName: "classify" */ '../views/Classify.vue'),
      },
      {
        path: 'cart',
        name: 'cart',
        component: () => import(/* webpackChunkName: "cart" */ '../views/Cart.vue'),
      },
      {
        path: 'personCenter',
        name: 'personCenter',
        component: () => import(/* webpackChunkName: "classify" */ '../views/PersonCenter.vue'),
      },
    ],
  },
  // 只要匹配不到上面的路由，就匹配我这个路由
  {
    path: '*',
    component: () => import('../views/404.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

export default router
